﻿using System.Windows;

namespace Projekt
{
    /// <summary>
    /// Interaktionslogik für Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {       
        private Extractor extractor;
        private WebpageData webpageData;

        public Window1()
        {
            InitializeComponent();
            txtURL.Focus();
            // Initialise Variables
            webpageData = new WebpageData();
            extractor = new Extractor();     
        }

        private void goButton_Click(object sender, RoutedEventArgs e)
        {
            // Disable Buttons
            textBtn.IsEnabled = false;
            headlinesBtn.IsEnabled = false;
            sourcecodeBtn.IsEnabled = false;
            wordCountBtn.IsEnabled = false;

            // Read URL from TextBox
            webpageData.URL = txtURL.Text;
            // Call method to load WebPage
            bool success = extractor.loadWebPage(webpageData);

            // If Webpage loaded successfully
            if (success)
            {
                // Disable Buttons
                textBtn.IsEnabled = true;
                headlinesBtn.IsEnabled = true;
                sourcecodeBtn.IsEnabled = true;
                wordCountBtn.IsEnabled = true;
            }
        }

        private void textBtn_Click(object sender, RoutedEventArgs e)
        {
            // Call method to extract and show plain text
            extractor.extractTextFromHTMLCode(webpageData);
        }

        private void headlinesBtn_Click(object sender, RoutedEventArgs e)
        {
            // Call method to read and show HeadLines
            extractor.extractHeadlinesFromHTMLCode(webpageData);
        }

        private void sourcecodeBtn_Click(object sender, RoutedEventArgs e)
        {
            // Call method to show HTML-Code
            extractor.showHTMLCode(webpageData);
        }

        private void wordCountBtn_Click(object sender, RoutedEventArgs e)
        {
            // Call method to count and show number of words
            Statistics.showStatistics(webpageData);            
        }

        private void txtURL_GotFocus(object sender, RoutedEventArgs e)
        {
            txtURL.Text = "";
        }

        private void txtURL_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
        {

        }                                                 
    }
}
